package org.webdb.webapp.jackson;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.SerializerProvider;
import org.postgis.LineString;

public class LineStringJSONSerializer {

    private PointComposedJSONSerializer pointSerializer;

    public LineStringJSONSerializer(PointComposedJSONSerializer pointSerializer) {
        this.pointSerializer = pointSerializer;
    }

    public void serialize(LineString lineString, JsonGenerator jgen,
            SerializerProvider provider) throws JsonGenerationException,
            IOException {
        jgen.writeStartObject();
        jgen.writeStringField(GEOJSON.TYPE_ATTRIBUTE,
                GEOJSON.LINESTRING_TYPE_NAME);
        jgen.writeFieldName(GEOJSON.COORDINATES_ATTRIBUTE);
        pointSerializer.writePointComposed(lineString, jgen);
        jgen.writeEndObject();
    }

}
